#pragma once
#ifndef __VERTEXBUFFER_H__
#define __VERTEXBUFFER_H__

#include "Utility.h"

#include "../util/PreDeclare.h"
#include "../util/D3DCommon.h"

namespace WindGE
{
	enum EVBType
	{
		evb_vertex,
		evb_index
	};

	class WIND_CORE_API VertexBuffer
	{
	public:
		VertexBuffer();
		~VertexBuffer();
		
		bool init(RenderDevicePtr renderDevice, EVBType type, bool isDynamic);
		bool build(const void* datas, unsigned int stride, unsigned int count);

		void bind_vertex(unsigned int slot, unsigned int offset);
		void bind_index(unsigned int offset);

		bool map(void** dataPtr, unsigned int mapType);
		bool unmap();

		inline bool			isdynamic() const { return isdynamic_;		}

		inline unsigned int stride()	const { return stride_;			}
		inline unsigned int count()		const { return count_;			}
		inline unsigned int size()		const { return stride_*count_;	}

	private:
		RenderDevicePtr				render_device_;
		EVBType						vb_type_;

		bool						isdynamic_;
		unsigned int				stride_;
		unsigned int				count_;
		
		ID3D11Buffer*				d3d_buffer_;
		D3D11_BUFFER_DESC			buffer_desc_;
		D3D11_MAPPED_SUBRESOURCE	mapped_resource_;
	};

}//end namespace WindGE

#endif // !__VERTEXBUFFER_H__
